package com.gl.saasservice.repository;


import com.gl.saasservice.entity.SmartLock;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface SmartLockRepository extends PagingAndSortingRepository<SmartLock, Long>, JpaSpecificationExecutor<SmartLock> {

    List<SmartLock> findBySnIn(List<String> sns);

    List<SmartLock> findByIdIn(List<Long> ids);

    SmartLock findBySn(String sn);

    List<SmartLock> findByHouseId(String houseId);
    List<SmartLock> findByOrgId(Long orgId);

    List<SmartLock> findByHouseIdOrMac(String houseId, String mac);

    SmartLock findByMac(String mac);

    @Query("from SmartLock where sn = ?1 and mechineStatus=?2")
    SmartLock findBySnAndMechineStatus(String sn,Integer mechineStatus);

    @Modifying
    @Query(value = "UPDATE saas_smart_lock SET mechine_status = ?2 WHERE id = ?1", nativeQuery = true)
    int updateMechineStatusById(Long id , Integer mechineStatus);
}
